package leetcode.editor.cn.q1_300.q150;

/**
 * @author qidi
 * @date 2022-01-19 15:20:23
 */
class Q0153_FindMinimumInRotatedSortedArray {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int findMin(int[] nums) {
            int l = 0;
            int r = nums.length - 1;
            while (l < r && nums[l] > nums[r]) {
                int m = (r + l) / 2;
                if (nums[l] > nums[m]) {
                    r = m;
                } else {
                    l = m + 1;
                }
            }

            return nums[l];
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0153_FindMinimumInRotatedSortedArray().new Solution();
        System.out.println(solution.findMin(new int[]{11, 13, 15, 17}));
        System.out.println(solution.findMin(new int[]{3, 4, 5, 1, 2}));
        System.out.println(solution.findMin(new int[]{4, 5, 6, 7, 0, 1, 2}));
        System.out.println(solution.findMin(new int[]{4, 0, 1, 2, 3}));
    }
}